package rea;

import java.awt.PointerInfo;
import java.util.Random;
import java.util.Scanner;

public class Josephus {
	private static class Node{
		public int no;
		public Node next;
		
		public Node(int no){
			this.no = no;
			this.next =null;
		}
	}
	public static void main(String[] args){
		/*
		Scanner input = new Scanner(System.in);
		System.out.println("taotal nums");
		int totalNum = input.nextInt();
		System.out.println("size");
		int cycleNum = input.nextInt();*/
		
		
		Random rand = new Random();
		int totalNum = rand.nextInt(30);
		int cycleNum =rand.nextInt(5);
		if(cycleNum <=1 || cycleNum >= totalNum){
			System.out.println("error");
			return ;
		}
		Node header = new Node(1);
		Node pointer = header;
		for(int i = 2 ;i<= totalNum ;i++){
			pointer.next = new Node(i);
			pointer = pointer.next;
		}
		pointer.next = header ;
		
		System.out.println(totalNum +" " + cycleNum); 
		System.out.println("order output");
		while(pointer != pointer.next){
			for ( int i =1 ;i <cycleNum ;i++){
				pointer =pointer.next;
			}
			System.out.println(pointer.next.no);
			pointer.next = pointer.next.next;
		}
		System.out.println(pointer.next.no);
	}
}
